package edu.pw.treegrid.client.report.view;

import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.Progressbar;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.Label;

public class ProgressWindow extends Window {

	private Progressbar progressbar;
	private Label message;
	
	public ProgressWindow() {
		initWindow();
	}

	private void initWindow() {
		this.setWidth100();  
		this.setHeight100();   
		this.setTitle("Trwa generowanie raportu");   
		this.setShowMinimizeButton(false);   
		this.setIsModal(true);
		this.setShowModalMask(true);
		this.centerInPage();
		this.setKeepInParentRect(true);
		this.setMembersMargin(5);
		
		VLayout horizontalBars = new VLayout(4);  
        horizontalBars.setWidth(600);
        horizontalBars.setHeight100();
          
        message = new Label("Trwa generowanie raportu");  
        message.setHeight(16);  
        horizontalBars.addMember(message);  
          
        progressbar = new Progressbar();  
        progressbar.setHeight(24);  
        progressbar.setVertical(false);
        
        horizontalBars.addMember(progressbar);
        
        this.addItem(horizontalBars);
	}
	
	public void start() {
		this.show();
		this.updateStatus("Trwa generowanie raportu ...", 0);
	}
	
	public void updateStatus(String message, int percentDone) {
		this.message.setTitle(message);
		this.progressbar.setPercentDone(percentDone);
	}
	
	public void updateStatus(int percentDone) {
		this.progressbar.setPercentDone(percentDone);
	}
	
	public void finish() {
		this.updateStatus("Zakończono", 100);
		this.hide();
	}

}
